package com.qidian.buy.order.controller;

import com.qidian.buy.order.service.IOrderService;
import com.qidian.buy.order.vo.OrderVO;
import com.qidian.buy.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 戴着假发的程序员
 * @since 2024-05-21
 */
@RestController
@RequestMapping("/order")
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @PostMapping("/add")
    public QdResult add(@RequestBody OrderVO vo, HttpServletRequest request){
        // 获取用户信息
        Long userId = new Long(request.getAttribute("userId").toString());
        vo.setUserId(userId);
        return orderService.saveOrder(vo);
    }
}
